package com.tssm.json;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.tssm.bean.SupplyBean;
import com.tssm.pojo.SarcSupplier;
import com.tssm.service.SarcSupplierService;
@Controller("userjson")
@Scope("prototype")
public class UserJson extends ActionSupport {

	private static final long serialVersionUID = 7002507261038531503L;
	@Resource
	private SarcSupplierService sarcsupplierService;
	
	private String account;
	
	private String email;
	
	private int userId;
	
	private String rand;
	
	private int isexist;
	
	public String finduser() throws Exception {
		SarcSupplier ssuser = sarcsupplierService.findUserIsExist(account);
		if (ssuser != null) {
			userId = ssuser.getSupplierid().intValue();
		}
		return SUCCESS;
	}
	
	public String findemail() throws Exception {
		boolean flag = sarcsupplierService.findEmailIsExist(email);
		if (flag) {
			isexist = 1;
		}
		return SUCCESS;
	}
	/**
	 * 
	 * 
	 * @方法说明: 检查验证码
	 * @return
	 * @throws Exception
	 * @作者:徐龙
	 * @日期:2011-9-13
	 */
	public String findrand() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		String random = (String) session.getAttribute("random"); // 从session里获取验证码
		if (!rand.toLowerCase().equals(random)) {
			isexist = 1;
		}
		return SUCCESS;
	}
	public String findAll() throws Exception{
		List<SupplyBean> sblist=sarcsupplierService.findAllSupply();
		for (SupplyBean sbean:sblist){
			System.out.println(sbean.getAccount()+"**************");
			System.out.println(sbean.getId()+"!!!!!!!!!11**************");
			System.out.println(sbean.getPassword()+"@@@@@@@@@@@@@**************");
		}
		
		return SUCCESS;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	
	public int getIsexist() {
		return isexist;
	}

	public void setIsexist(int isexist) {
		this.isexist = isexist;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getRand() {
		return rand;
	}

	public void setRand(String rand) {
		this.rand = rand;
	}
	
}
